package com.example.everying.controller.statistics;/*
 * 项目名称: everything
 * 文件名: UserStatisticController
 * 作者: 张泽阳
 * 日期: 2025/7/5
 * 描述:
 */

import com.example.everying.annotation.WebLog;
import com.example.everying.model.dto.statistics.UserStatDto;
import com.example.everying.service.statistics.UserSessionService;
import com.example.everying.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(tags = "后端管理统计")
@RequestMapping("/statistics/user")
public class UserStatisticController {

    @Autowired
    private UserSessionService userSessionService;

    @WebLog(description = "记录用户登录")
    @PostMapping("/recordLogin")
    public Result<?> recordLogin(){
        return userSessionService.recordLogin();
    }

    @WebLog(description = "记录用户登出")
    @PostMapping("recordLogout")
    public Result<?> recordLogout(){
        return userSessionService.recordLogout();
    }

    /**
     * 获取用户平均使用时间
     * @return
     */
    @WebLog(description = "用户平均使用时间")
    @PostMapping("averageUseTime")
    public Result<?> averageUseTime(){
        return userSessionService.averageUseTime();
    }

    /**
     * 近七天所有用户登录次数
     * @return
     */
    @WebLog(description = "近七天所有用户登录次数")
    @PostMapping("/loginCount")
    public Result<?> loginCount(){
        return userSessionService.loginCount();
    }

    /**
     * 次日留存率
     * @return
     */
    @WebLog(description = "次日留存率")
    @PostMapping("/rr1")
    public Result<?> rr1(){
        return userSessionService.rr1();
    }

    /**
     * 7日留存率
     * @return
     */
    @WebLog(description = "次日留存率")
    @PostMapping("/rr7")
    public Result<?> rr7(){
        return userSessionService.rr7();
    }

    /**
     * 单位时间内用户在线数量
     * @return
     */
    @WebLog(description = "用户在线数量")
    @PostMapping("onlineUserCount")
    public Result<?> onlineUserCount(){
        return userSessionService.onlineUserCount();
    }



    /**
     * 发过帖子的用户÷用户总数 x100%
     * @return
     */
    @WebLog(description = "转化率")
    @PostMapping("conversionStatistics")
    public Result<?> conversionStatistics(){
        return userSessionService.conversionStatistics();
    }
    /**
     * 完成的悬赏÷发布的悬赏任务总数
     * @return
     */
    @WebLog(description = "完成率")
    @PostMapping("completionRate")
    public Result<?> completionRate(){
        return userSessionService.completionRate();
    }
    /**
     * GMV(商品交易总额)
     * @return
     */
    @WebLog(description = "交易总额")
    @PostMapping("totalAmount")
    public Result<?> totalAmount(){
        return userSessionService.totalAmount();
    }
    /**
     * 复发率(文字帖)=重复发帖用户数(>2)÷总发文字帖用户数 X100%
     * @return
     */
    @WebLog(description = "帖子复发率")
    @PostMapping("recurrentRate")
    public Result<?> recurrentRate(){
        return userSessionService.recurrentRate();
    }
    /**
     * 复购率(悬赏)=重复发悬赏用户数(>2)÷总发悬赏的用户数 x100%
     * @return
     */
    @WebLog(description = "悬赏复购率")
    @PostMapping("repurchaseRate")
    public Result<?> repurchaseRate(){
        return userSessionService.repurchaseRate();
    }

    @ApiOperation(value = "统计用户近一周登录次数")
    @WebLog(description = "用户近一周登录次数")
    @PostMapping("/userLoginCount")
    public Result<?> userLoginCount(@RequestBody UserStatDto userStatDto){
        return userSessionService.userLoginCount(userStatDto);
    }

    @ApiOperation(value = "统计用户近一周登录时长")
    @WebLog(description = "用户近一周登录时长")
    @PostMapping("/userLoginDuration")
    public Result<?> userLoginDuration(@RequestBody UserStatDto userStatDto){
        return userSessionService.userLoginDuration(userStatDto);
    }

    @ApiOperation(value = "获取今日浏览量前十文章")
    @WebLog(description = "获取今日浏览量前十文章")
    @PostMapping("/getTopTenArticle")
    public Result<?> getTopTenArticle(){
        return userSessionService.getTopTenArticle();
    }

}
